/*
  单选
 */

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
      // home: HomePage2(),
    );
  }
}

// 一般用法
class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _sex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Radio'),
      ),
      body: Row(
        children: [
          Text('男:'),
          Radio(
              value: 0,
              groupValue: _sex,
              onChanged: (int? v) {
                setState(() {
                  _sex = v!;
                });
              }),
          Text('女:'),
          Radio(
              value: 1,
              groupValue: _sex,
              onChanged: (int? v) {
                setState(() {
                  _sex = v!;
                });
              })
        ],
      ),
    );
  }
}

// 更多内容，使用 RadioListTile
// checkbox 也有 CheckBoxListTile
class HomePage2 extends StatefulWidget {
  @override
  _HomePage2State createState() => _HomePage2State();
}

class _HomePage2State extends State<HomePage2> {
  int _selected = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Radio'),
      ),
      body: Column(
        children: [
          RadioListTile(
              title: Text('标题一'),
              subtitle: Text('副标题'),
              value: 0,
              groupValue: _selected,
              onChanged: (int? v) {
                setState(() {
                  _selected = v!;
                });
              }),
          RadioListTile(
              title: Text('标题二'),
              subtitle: Text('副标题'),
              value: 1,
              groupValue: _selected,
              onChanged: (int? v) {
                setState(() {
                  _selected = v!;
                });
              })
        ],
      ),
    );
  }
}
